#pragma once

#include "instructions/base/instructions.h"
#include "rtda/frame.h"

namespace jvm {
    namespace instructions {
        class MULTI_ANEW_ARRAY : public Instruction {
        private:
            uint16_t m_index;
            uint8_t m_dimensions;
        public:
            void fetchOperands(std::shared_ptr<BytecodeReader> reader) override;
            void execute(std::shared_ptr<rtda::Frame> pframe) override;
        private:
            static std::vector<int32_t> popAndCheckCounts(std::shared_ptr<rtda::OperandStack> pstack, int dimensions);
            static heap::ObjectPtr newMultiDimensionalArray(
                const std::vector<int32_t>& counts, std::shared_ptr<heap::Class> arrClass);
        };
    } // namespace instructions
}// namespace jvm